/**
 * Created by hejiahui on 2018/6/24.
 */

var db =  require('../connect')

const Schema = db.Schema

//account对应的字段
const taskSchema = new Schema(
    {
        title: { type: Schema.Types.Mixed , maxlength: 50 },
        userId: { type: String },
        grade: { type: String, maxlength: 20 },
        desc: { type: String, maxlength: 20 },
        location : { type: String, maxlength: 20 },
        arrivalTime : { type: Number, maxlength: 20 },
        arriveDate : { type: String },
        create_date: { type: Number },
        update_date: { type: Number }
    },
    {
        versionKey: false
    }
)

//当account执行save()前，执行该代码片段，有点类似于中间件(这个方法内容仅仅是介绍pre()的使用方法)
taskSchema.pre('save', function(next) {
        const currentDate = +new Date()
        if (!this.create_date) {
                this.create_date = currentDate
        } else {
                this.update_date = currentDate
        }
        next()
})

taskSchema.set('collection', 'task')
const Task = db.model('task', taskSchema)

module.exports = Task